﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:o="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
    xmlns:l="http://wpflocalizeextension.codeplex.com"
    xmlns:local="clr-namespace:Imagin.Controls.Extended"
    xmlns:Common.Data.Converters="clr-namespace:Imagin.Common.Data.Converters;assembly=Imagin.Common"
    xmlns:Common.Extensions="clr-namespace:Imagin.Common.Extensions;assembly=Imagin.Common"
    xmlns:Controls.Common.Extensions="clr-namespace:Imagin.Controls.Common.Extensions;assembly=Imagin.Controls.Common">
    <Common.Data.Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    <Common.Data.Converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
    
    <Style x:Key="{x:Type local:TabbedTree}" TargetType="{x:Type local:TabbedTree}">
        <Setter Property="Controls.Common.Extensions:TreeViewItemExtensions.CollapseSiblingsOnClick" Value="False"/>
        <Setter Property="Controls.Common.Extensions:TreeViewItemExtensions.ExpandOnClick" Value="False"/>
        <Setter Property="HorizontalAlignment" Value="Stretch"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Visible"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Visible"/>
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="VirtualizingPanel.IsVirtualizing" Value="True"/>
        <Setter Property="VirtualizingPanel.VirtualizationMode" Value="Recycling"/>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel IsItemsHost="True"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:TabbedTree}">
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        Padding="{TemplateBinding Padding}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="{TemplateBinding MenuWidth}"/>
                                <ColumnDefinition Width="{TemplateBinding ContentWidth}"/>
                            </Grid.ColumnDefinitions>
                            <ScrollViewer 
                                VerticalAlignment="Stretch"
                                BorderThickness="{TemplateBinding MenuBorderThickness}" 
                                Background="{TemplateBinding MenuBackground}" 
                                BorderBrush="{TemplateBinding MenuBorderBrush}"
                                Focusable="False" 
                                CanContentScroll="True">
                                <ItemsPresenter 
                                    Margin="{TemplateBinding MenuPadding}" 
                                    HorizontalAlignment="Stretch"/>
                            </ScrollViewer>

                            <GridSplitter
                                x:Name="PART_GridSplitter"
                                HorizontalAlignment="Right"
                                ResizeBehavior="CurrentAndNext"
                                ResizeDirection="Columns"
                                VerticalAlignment="Stretch"
                                Width="{TemplateBinding SplitterWidth}"/>

                            <Border 
                                Grid.Column="1"
                                Padding="{TemplateBinding ContentPadding}" 
                                BorderThickness="{TemplateBinding ContentBorderThickness}" 
                                Background="{TemplateBinding ContentBackground}" 
                                BorderBrush="{TemplateBinding ContentBorderBrush}">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <ContentControl
                                        x:Name="PART_ContentHeader"
                                        ContentTemplate="{TemplateBinding ContentHeaderTemplate}"
                                        Visibility="{TemplateBinding ContentHeaderVisibility}"/>
                                    <ContentControl
                                        Grid.Row="1"
                                        x:Name="PART_Content"
                                        Content="{TemplateBinding SelectedItem}">
                                        <ContentControl.Resources>
                                            <DataTemplate x:Key="DefaultContentTemplate">
                                                <ContentControl Content="{Binding Path=(Controls.Common.Extensions:ControlExtensions.Content), Mode=OneWay}"/>
                                            </DataTemplate>
                                        </ContentControl.Resources>
                                        <ContentControl.Style>
                                            <Style TargetType="ContentControl">
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding ContentTemplate, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource NullToBooleanConverter}}" Value="True">
                                                        <Setter Property="ContentTemplate" Value="{Binding ContentTemplate, RelativeSource={RelativeSource TemplatedParent}}"/>
                                                    </DataTrigger>
                                                    <DataTrigger Binding="{Binding ContentTemplate, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource NullToBooleanConverter}}" Value="False">
                                                        <Setter Property="ContentTemplate" Value="{StaticResource DefaultContentTemplate}"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </ContentControl.Style>
                                    </ContentControl>
                                </Grid>
                            </Border>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ColumnResizeMode" Value="None">
                            <Setter TargetName="PART_GridSplitter" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="ColumnResizeMode" Value="Resize">
                            <Setter TargetName="PART_GridSplitter" Property="ShowsPreview" Value="False"/>
                            <Setter TargetName="PART_GridSplitter" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="ColumnResizeMode" Value="ResizeWithPreview">
                            <Setter TargetName="PART_GridSplitter" Property="ShowsPreview" Value="True"/>
                            <Setter TargetName="PART_GridSplitter" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="ContentHeaderTemplate" Value="{x:Null}">
                            <Setter TargetName="PART_ContentHeader" Property="ContentTemplate">
                                <Setter.Value>
                                    <DataTemplate>
                                        <ContentPresenter Content="{Binding Mode=OneWay}"/>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <Trigger Property="SelectedItem" Value="{x:Null}">
                            <Setter TargetName="PART_Content" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="PART_ContentHeader" Property="Visibility" Value="Collapsed"/>
                        </Trigger> 
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>